package com.ww.demo.newcoder;

import java.util.Scanner;

public class Main5 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        String sub = str.substring(2);
        char[] charStr = sub.toCharArray();
        int sum = 0;
        for (int i = 0; i < charStr.length; i++) {
            int hexValue = getValue(charStr[i]);
            int tenValue = hexValue * getHexValue(charStr.length - 1 - i);
            sum = sum + tenValue;
        }
        System.out.println(sum);
    }

    private static int getHexValue(int len) {
        int sum = 1;
        for (int i = 0; i < len; i++) {
            sum = sum * 16;
        }
        return sum;
    }

    private static int getValue(char val) {
        int result = 0;
        if (Character.isDigit(val) && Integer.valueOf(String.valueOf(val)) < 10) {
            return Integer.valueOf(String.valueOf(val));
        }
        switch (val) {
            case 'A':
                result = 10;
                break;
            case 'B':
                result = 11;
                break;
            case 'C':
                result = 12;
                break;
            case 'D':
                result = 13;
                break;
            case 'E':
                result = 14;
                break;
            case 'F':
                result = 15;
                break;
        }
        return result;

    }

}
